package com.maple.user.controller;


import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.maple.user.entity.SysUser;
import com.maple.user.service.ISysUserService;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author maple
 * @since 2023-03-24
 */
@RestController
@RequestMapping("/user")
public class SysUserController {

    @Resource
    private ISysUserService sysUserService;

    @RequestMapping("/list/all")
    @ResponseBody
    public List<SysUser> list() {
        return sysUserService.listAll();
    }

    @RequestMapping("/list")
    @ResponseBody
    public List<SysUser> listDemo() {
        return sysUserService.list();
    }

    @RequestMapping("/page")
    @ResponseBody
    public Page<SysUser> listDemo(Page<SysUser>  page) {
        page.setCurrent(1);
        page.setSize(2);

        List<OrderItem> orderItems = new ArrayList<>();
        OrderItem orderItem = new OrderItem();
        orderItem.setAsc(false);
        orderItem.setColumn("age");
        orderItems.add(orderItem);
        page.setOrders(orderItems);

        return sysUserService.page(page);
    }
}
